/**
 * @FileName index.js
 * @Description
 * @Author renminghe
 * @Date 2018-12-29 14:18
 * @Version 1.0
 * @Copyright(c) gome inc Gome Co.,LTD
 **/

import Vue from "vue"
import Vuex from "vuex"

import EditorDefaultConfig from "@/config/editorDefaultConfig.js";

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        activeList: [],
        resetMap: {},
    },

    mutations: {
        edited (state, actionData) {

            if (state.activeList.length === EditorDefaultConfig.cancelCount) {

                state.activeList.splice(0, 1);

            }

            state.activeList.push(actionData);
        },

        pushResetList (state, changeTarget) {

            if (!state.resetMap[changeTarget.target.name + "&" + changeTarget.target.type]) {

                state.resetMap[changeTarget.target.name + "&" + changeTarget.target.type] = JSON.parse(JSON.stringify(changeTarget.target));
            }
        },

    },

    actions: {
        edited (context, actionDatat) {
            context.commit('edited', actionDatat);
        },

        pushResetList (context, changeTarget) {
            context.commit('pushResetList', changeTarget);
        },
    }
});